import {LogLanguage} from "../dist/index.js"

// 测试用例
const testCases = [
  // 字符串测试
  'INFO User login with id="12345" and name="John Doe"',
  'ERROR Database connection failed: "Connection timeout"',
  'DEBUG Processing request: `{"id": 123, "status": "pending"}`',
  'WARN Invalid input: \'user@example.com\'',
  
  // 数值测试
  'INFO Request processed in 123.45ms',
  'ERROR Failed after 3 attempts',
  'DEBUG Memory usage: 1024.5MB',
  'INFO Response time=0.123s',
  'ERROR Error code: 404',
  'DEBUG Batch size: 1000',
  'INFO Temperature: 25.6°C',
  'ERROR Retry count: 5',
  
  // 混合测试
  'INFO User "john_doe" processed 123 items in 45.67 seconds',
  'ERROR Service "auth-service" failed with code=500 after 3.14s',
  'DEBUG Request {"id": 123, "timeout": 30.0} completed',
  
  // 复杂日志行
  '2024-01-15T10:30:45.123+0800 INFO [TID:abc123] [service.AuthService] User "admin" logged in with session_id="sess_456" after 0.25s'
]

console.log("Testing String and Number recognition...")

testCases.forEach((testCase, index) => {
  console.log(`\nTest case ${index + 1}:`)
  console.log(`Input: ${testCase}`)
  
  try {
    const tree = LogLanguage.parser.parse(testCase)
    console.log("Parse successful!")
    
    // 检查识别到的元素
    let foundStrings = []
    let foundNumbers = []
    let foundClassPaths = []
    
    tree.iterate({
      enter: (node) => {
        const text = testCase.slice(node.from, node.to)
        switch (node.name) {
          case "StringExpression":
            foundStrings.push(text)
            break
          case "NumberExpression":
            foundNumbers.push(text)
            break
          case "CLASSPATHExpression":
            foundClassPaths.push(text)
            break
        }
      }
    })
    
    if (foundStrings.length > 0) {
      console.log(`✅ Found ${foundStrings.length} string(s): ${foundStrings.join(', ')}`)
    }
    
    if (foundNumbers.length > 0) {
      console.log(`✅ Found ${foundNumbers.length} number(s): ${foundNumbers.join(', ')}`)
    }
    
    if (foundClassPaths.length > 0) {
      console.log(`✅ Found ${foundClassPaths.length} class path(s): ${foundClassPaths.join(', ')}`)
    }
    
    if (foundStrings.length === 0 && foundNumbers.length === 0 && foundClassPaths.length === 0) {
      console.log("❌ No special elements found")
    }
    
  } catch (error) {
    console.log(`Parse failed: ${error.message}`)
  }
}) 